package com.karrim.server;

import com.google.inject.Singleton;
import com.karrim.server.abstr.AbstractDispatcher;
import com.karrim.server.util.def.Listener;
import java.util.Iterator;

@Singleton
public class SocketConnectionEventDispatcher extends AbstractDispatcher<SocketConnectionEvent, SocketConnectionListener> {

    public SocketConnectionEventDispatcher() {
        super("SocketConnectionEventDispatcher", 10);
    }

    @Override
    public void dispatch(SocketConnectionEvent event) {
        this.event = event;
        run();
    }

    @Override
    public void run() {
        Iterator<Listener> iterator = listeners.iterator();
        while (iterator.hasNext()) {
            ((SocketConnectionListener) iterator.next()).onSocketConnection(event);
        }
    }
    private SocketConnectionEvent event;
}